class Shot extends Animation {
   
    boolean active;
    byte type, explosionIndex;
    int aX, aY, bX, bY, edgeFirstIndex, itemFirstIndex, stepY, counter;
    Ship owner;
   
/**************************************************************************************************/

    public boolean activate(Ship ship, byte type, int index) {
        boolean flag = false;
        switch (type) {
            case Constants.WEAPON_LASER:
                if (ship.shooter.isReady()) {
                    aX = bX = ship.posX;
                    aY = bY = ship.posY;
                    explosionIndex = (byte)index;
                    if (explosionIndex < GameScreen.explosions.length) GameScreen.explosions[explosionIndex].reserved = true;
                    ship.shooter.start();
                    flag = true;
                }
            break;
            
            case Constants.WEAPON_ROCKET:
                if (ship.shooter.isReady() && ship.weaponCount > 0) {
                    aX = bX = ship.posX;
                    aY = bY = ship.posY;
                    startAnimation(Constants.A_ROCKET, Constants.ANIMATION_PLAY_REPEAT);
                    ship.shooter.start();
                    stepY = ship.stepY + 10;
                    if (!GameScreen.cheat_Missiles) ship.weaponCount--;
                    flag = true;
                }
            break;
         
            case Constants.WEAPON_BOMB:
                if (ship.shooter.isReady() && ship.weaponCount > 0) {
                    aX = ship.posX - (Constants.BOMB_WIDTH >> 1);
                    bX = ship.posX + (Constants.BOMB_WIDTH >> 1);
                    aY = bY = ship.leftPosY;
                    startAnimation(Constants.A_BOMB, Constants.ANIMATION_PLAY_REPEAT);
                    ship.shooter.start();
                    if (!GameScreen.cheat_Bomb) ship.weaponCount--;
                    counter = 1000;
                    flag = true;
                }
            break;
         
            case Constants.WEAPON_MINE:
                if (ship.shooter.isReady() && ship.weaponCount > 0) {
                    aX = ship.leftPosX - ship.leftDistance;
                    bX = ship.rightPosX + ship.rightDistance;
                    aY = bY = ship.leftPosY;
                    stepY = ship.posX;
                    ship.shooter.start();
                    if (!GameScreen.cheat_Mine) ship.weaponCount--;
                    flag = true;
                }
            break;
        }
        if (flag) {
            owner = ship;
            edgeFirstIndex = ship.borderFirstIndex;
            itemFirstIndex = ship.firstTrackItem;
            this.type = type;
            active = true;
            return true;
        }
        return false;
    }

/**************************************************************************************************/

    public void deactivate() {
        active = false;
        switch (type) {
            case Constants.WEAPON_LASER:
                if (explosionIndex < GameScreen.explosions.length) GameScreen.explosions[explosionIndex].reserved = false;
            case Constants.WEAPON_ROCKET:
                owner.shooter.stop();
            break;
            case Constants.WEAPON_MINE:
            case Constants.WEAPON_BOMB:
                owner.shooter.stop();
            break;
        }
    }

/**************************************************************************************************/

    public boolean detectShipHit(Ship ship) {
        return ship.shipVisible & ship.leftPosX <= aX && aX <= ship.rightPosX && aY <= ship.posY && ship.leftPosY <= bY;
    }

/**************************************************************************************************/

    public void update(long dt) {
        updateAnimation(dt);
        edgeFirstIndex = owner.borderFirstIndex;
        itemFirstIndex = owner.firstTrackItem;
        switch (type) {
            case Constants.WEAPON_LASER:
                if (owner.shooter.isEmpty()) {
                    deactivate();
                }
                else {
                    bX = aX = owner.posX;
                    aY = owner.posY;
                    bY = GameScreen.maxShipPosY;
                }
            break;
            
            case Constants.WEAPON_ROCKET:
                aY = bY;
                bY += stepY;
            break;

            case Constants.WEAPON_BOMB:
                counter -= dt;
            break;
        }
    }
}